/*
 * Copyright (C) 2011 CrystalRange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.crystalrange.enterprise.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.enterprise.dao.QuantDao;
import org.crystalrange.enterprise.model.Quant;
import org.crystalrange.enterprise.service.QuantService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

public class QuantServiceImpl implements QuantService {

    private QuantDao quantDao;
    private UserService userService;

    public void setQuantDao(QuantDao quantDao) {
        this.quantDao = quantDao;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public Quant create(String username) {
        
        User currentUser = this.userService.findByUsername(username);  
        
        Quant quant = new Quant();
        quant.setCreatedBy(currentUser);
        quant.setCreatedDate(new Date());
        
        return quant;
    }
    
    public void save(Quant quant, String username) {
        
        User currentUser = this.userService.findByUsername(username);  
        
        quant.setUpdatedBy(currentUser);
        quant.setUpdatedDate(new Date());
        
        this.quantDao.save(quant);
    }

    public void remove(Quant quant) {
        this.quantDao.remove(quant);
    }

    public Quant find(Long id) {
        return this.quantDao.find(id);
    }

    public List<Quant> findAll() {
        return this.quantDao.findAll();
    }

    public SearchResult<Quant> searchAndCount(Search search) {
        return this.quantDao.searchAndCount(search);
    }
    
    public List<Quant> search(Search search) {
        return this.quantDao.search(search);
    }

    public Quant searchUnique(Search search) {
        return this.quantDao.searchUnique(search);
    }
}
